package com.example.scoredemo

import android.app.Application
import android.content.Context
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel

class MyViewModel(application: Application) : AndroidViewModel(application) {


    var aTeamSorce = MutableLiveData<Int>()
    var bTeamSorce = MutableLiveData<Int>()
    var sorceA = 0
    var sorceB = 0


    init {
        aTeamSorce.value = sorceA
        bTeamSorce.value = sorceB
    }



    public fun aTeamAddSorce(x: Int) {
        sorceA = aTeamSorce.value!!
        sorceB = bTeamSorce.value!!
        aTeamSorce.value = (aTeamSorce.value!! + x)
        if (aTeamSorce.value!! < 0) {
            aTeamSorce.value = 0
        }
    }

    public fun bTeamAddSorce(x: Int) {
        sorceA = aTeamSorce.value!!
        sorceB = bTeamSorce.value!!
        bTeamSorce.value = (bTeamSorce.value!! + x)
        if (bTeamSorce.value!! < 0) {
            bTeamSorce.value = 0
        }
        getApplication<Application>().getSharedPreferences("muzi", Context.MODE_PRIVATE);
    }

    public fun reset() {
        sorceA = aTeamSorce.value!!
        sorceB = bTeamSorce.value!!
        aTeamSorce.value = 0
        bTeamSorce.value = 0
    }

    public fun undo() {
        aTeamSorce.value = sorceA
        bTeamSorce.value = sorceB
    }
}